package com.shensi.adminCollect.controller.integral;

import com.alibaba.fastjson.JSONObject;
import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.common.utils.StringUtils;
import com.shensi.adminCollect.common.utils.poi.ExcelUtil;
import com.shensi.adminCollect.domain.integral.IntegralRule;
import com.shensi.adminCollect.domain.integral.IntegralRuleDetail;
import com.shensi.adminCollect.domain.integral.IntegralTimeRuleDetail;
import com.shensi.adminCollect.service.integral.IIntegralRuleService;
import com.shensi.adminCollect.domain.system.SysEnterpriseUser;
import com.shensi.adminCollect.domain.system.SysOil;
import com.shensi.adminCollect.service.system.ISysDeptService;
import com.shensi.adminCollect.service.system.ISysEnterpriseUserService;
import com.shensi.adminCollect.service.system.ISysOilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

import com.shensi.common.core.domain.model.LoginUser;
import com.shensi.common.core.utils.SecurityUtils;

/**
 * 积分规则Controller
 *
 * @author qujia
 * @date 2021-02-24
 */
@RestController
@RequestMapping("/integral/rule")
public class IntegralRuleController extends BaseController
{
    @Autowired
    private IIntegralRuleService integralRuleService;
    @Autowired
    private ISysDeptService sysDeptService;
    @Autowired
    private ISysEnterpriseUserService sysEnterpriseUserService;

    @Autowired
    private ISysOilService sysOilService;
    /**
     * 查询积分规则列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IntegralRule integralRule)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        /*SysDept sysDept = sysDeptService.selectDeptById(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.deptIntegralInfoList(sysDept);
        if(list!=null && list.size()>0){
            integralRule.setStationIdList(list);
            integralRule.setStationId(null);
        }*/
        integralRule.setStationId(currentUser.getUser().getEnterpriseId());
        startPage();
        List<IntegralRule> integralRuleList = integralRuleService.selectIntegralRuleList(integralRule);
        return getDataTable(integralRuleList);
    }

    /**
     * 查询积分规则明细
     * @param integralRule
     * @return
     */
    @GetMapping("/listRuleInfo")
    public TableDataInfo listRuleInfo(IntegralRule integralRule)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();

        integralRule.setStationId(currentUser.getUser().getEnterpriseId());
//        SysDept dept =new SysDept();
//        dept.setDeptId(currentUser.getUser().getDeptId());
//        List<String> list = sysDeptService.selectDeptId(dept);
//        if(list!=null && list.size()>0){
//            integralRule.setStationIdList(list);
//            integralRule.setStationId(null);
//        }
        startPage();
        List<IntegralRule> integralRuleList = integralRuleService.listRuleInfo(integralRule);
        return getDataTable(integralRuleList);
    }

    @GetMapping("/listRuleOne")
    public AjaxResult listRuleOne(IntegralRule integralRule)
    {

        LoginUser currentUser = SecurityUtils.getLoginUser();
        if(!"1".equals(currentUser.getUser().getUserLevel())){
            return  AjaxResult.error("当前用户无法查看设置");
        }
        integralRule.setStationId(currentUser.getUser().getEnterpriseId());
        IntegralRule rule = integralRuleService.selectIntegralRule(integralRule);
        return AjaxResult.success(rule);
    }
    /**
     * 导出积分规则列表
     */
    @GetMapping("/export")
    public AjaxResult export(IntegralRule integralRule)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        /*SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            integralRule.setStationIdList(list);
            integralRule.setStationId(null);
        }*/
        integralRule.setStationId(currentUser.getUser().getEnterpriseId());
        List<IntegralRule> integralRuleList = integralRuleService.selectIntegralRuleList(integralRule);
        ExcelUtil<IntegralRule> util = new ExcelUtil<IntegralRule>(IntegralRule.class);
        return util.exportExcel(integralRuleList, "rule");
    }

    /**
     * 获取积分规则详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(integralRuleService.selectIntegralRuleById(id));
    }

    /**
     * 新增积分规则
     */
    @PostMapping
    @Transactional
    public AjaxResult add(@RequestBody IntegralRule integralRule)
    {
        String check = check(integralRule);
        if(StringUtils.isNotEmpty(check)){
            return AjaxResult.error(check);
        }
        LoginUser currentUser = SecurityUtils.getLoginUser();
        integralRule.setStationId(currentUser.getUser().getEnterpriseId());
        if(integralRule!=null && integralRule.getIntegralActivity()==null){
            integralRule.setIntegralActivity("0");
        }
        if(integralRule!=null &&integralRule.getIntegralFlag()!=null && !integralRule.getIntegralFlag().equals("")){
            SysEnterpriseUser sysEnterpriseUser=new SysEnterpriseUser();
            sysEnterpriseUser.setEnterpriseId(currentUser.getUser().getEnterpriseId());
            sysEnterpriseUser.setIntegralFlag(integralRule.getIntegralFlag());
            sysEnterpriseUserService.updateSysEnterpriseUser(sysEnterpriseUser);
        }
        int i=integralRuleService.insertIntegralRule(integralRule);
        return toAjax(i);
    }

    /**
     * 修改积分规则
     */
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralRule integralRule)
    {

        String check = check(integralRule);
        if(StringUtils.isNotEmpty(check)){
            return AjaxResult.error(check);
        }


        LoginUser currentUser = SecurityUtils.getLoginUser();
        int i =0;
        if(integralRule!=null&&integralRule.getIntegralFlag()!=null && !integralRule.getIntegralFlag().equals("")){
            if(integralRule.getIntegralFlag().equals("1")){
                SysEnterpriseUser sysEnterpriseUser=new SysEnterpriseUser();
                sysEnterpriseUser.setEnterpriseId(currentUser.getUser().getEnterpriseId());
                sysEnterpriseUser.setIntegralFlag(integralRule.getIntegralFlag());
                i=sysEnterpriseUserService.updateSysEnterpriseUser(sysEnterpriseUser);
                if(integralRule!=null && integralRule.getIntegralActivity()==null){
                    integralRule.setIntegralActivity("0");
                    integralRule.setDatePickerTime("");
                    i= integralRuleService.updateIntegralRule(integralRule);
                }else if(integralRule!=null){
                    i= integralRuleService.updateIntegralRule(integralRule);
                }
            }else if(integralRule.getIntegralFlag().equals("0")){
                SysEnterpriseUser sysEnterpriseUser=new SysEnterpriseUser();
                sysEnterpriseUser.setEnterpriseId(currentUser.getUser().getEnterpriseId());
                sysEnterpriseUser.setIntegralFlag(integralRule.getIntegralFlag());
                i=sysEnterpriseUserService.updateSysEnterpriseUser(sysEnterpriseUser);
            }
        }
        return toAjax(i);
    }

    public String check(IntegralRule integralRule){
        SimpleDateFormat dateFormat2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat1=new SimpleDateFormat("yyyy-MM-dd");
        String ymd = dateFormat1.format(new Date());
        //校验油品不能重复
        List<IntegralRuleDetail> itemsDetail = integralRule.getItemsDetail();
        if(itemsDetail!=null&&itemsDetail.size()>0){
            for (IntegralRuleDetail integralRuleDetail : itemsDetail) {
                Long oilId = integralRuleDetail.getOilId();
                if(oilId!=null){
                    SysOil sysOil = sysOilService.selectSysOilById(oilId);
                    integralRuleDetail.setOilName(sysOil.getOilName());
                }
            }
            Map<String, List<IntegralRuleDetail>> collect = itemsDetail.stream().collect(Collectors.groupingBy(i -> i.getOilName()));
            for (List<IntegralRuleDetail> value : collect.values()) {
                if(value.size()>1){
                  /*  return "油品不能重复";*/
                    //比较时间重复
                    for (int i = 0; i < value.size(); i++) {
                        List<IntegralRuleDetail> details = JSONObject.parseArray(JSONObject.toJSONString(value), IntegralRuleDetail.class);
                        details.remove(i);
                        IntegralRuleDetail integralRuleDetail = value.get(i);
                        for (IntegralRuleDetail detail : details) {
                            if(!checkTime(integralRuleDetail,detail)){
                                return "生效时间存在冲突！";
                            }
                        }
                    }
                }
                //校验时间段
                for (IntegralRuleDetail integralRuleDetail : value) {
                    List<IntegralTimeRuleDetail> integralTimeRuleDetails =integralRuleDetail.getIntegralTimeRuleDetails();
                    if(integralTimeRuleDetails != null &&integralTimeRuleDetails.size()>0){
                        for (int i = 0; i < integralTimeRuleDetails.size(); i++) {
                            List<IntegralTimeRuleDetail> temp = JSONObject.parseArray(JSONObject.toJSONString(integralTimeRuleDetails), IntegralTimeRuleDetail.class);
                            temp.remove(i);
                            IntegralTimeRuleDetail detail = integralTimeRuleDetails.get(i);
                            for (IntegralTimeRuleDetail tempDetail : temp) {
                                //校验时间交集
                                if(detail.getEffectiveDateStart()!=null){
                                    Date start = detail.getEffectiveDateStart();
                                    Date end = detail.getEffectiveDateEnd();
                                    Date startTemp = tempDetail.getEffectiveDateStart();
                                    Date endTemp = tempDetail.getEffectiveDateEnd();
                                    if(start.getTime()<=startTemp.getTime()&&startTemp.getTime()<end.getTime()){
                                        return "生效时间存在冲突！";
                                    }
                                    if(start.getTime()<endTemp.getTime()&&endTemp.getTime()<=end.getTime()){
                                        return "生效时间存在冲突！";
                                    }
                                }
                                if(detail.getEffectiveTimeStart()!=null){
                                    Date start = localTimeToDate(detail.getEffectiveTimeStart());
                                    Date end = localTimeToDate(detail.getEffectiveTimeEnd());
                                    Date startTemp = localTimeToDate(tempDetail.getEffectiveTimeStart());
                                    Date endTemp = localTimeToDate(tempDetail.getEffectiveTimeEnd());
                                    //[start,end)
                                    if(start.getTime()<=startTemp.getTime()&&startTemp.getTime()<end.getTime()){
                                        return "生效时间存在冲突！";
                                    }
                                    if(start.getTime()<endTemp.getTime()&&endTemp.getTime()<=end.getTime()){
                                        return "生效时间存在冲突！";
                                    }
                                }
                            }

                        }
                    }
                }
            }
        }
        return null;
    }

    public boolean checkTime(IntegralRuleDetail detail1,IntegralRuleDetail detail2){
        SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
        String effectiveTimeType1 = detail1.getEffectiveTimeType();
        String effectiveTimeType2 = detail2.getEffectiveTimeType();
        if(effectiveTimeType1.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_PERMANENT_VALIDITY)||
                effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_PERMANENT_VALIDITY)){
            return false;
        }
        boolean result = true;
        List<IntegralTimeRuleDetail> integralTimeRuleDetails = detail1.getIntegralTimeRuleDetails();


        if(effectiveTimeType1.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_SPECIFY_TIME)){
            if(integralTimeRuleDetails!=null&&integralTimeRuleDetails.size()>0){
                for (IntegralTimeRuleDetail detail : integralTimeRuleDetails) {
                    Date dateStart = detail.getEffectiveDateStart();
                    Date dateEnd = detail.getEffectiveDateEnd();
                    LocalTime timeStart = dateToLocalTime(dateStart);
                    LocalTime timeEnd = dateToLocalTime(dateEnd);
                    List<IntegralTimeRuleDetail> temp = detail2.getIntegralTimeRuleDetails();
                    if(temp!=null&&temp.size()>0){
                        for (IntegralTimeRuleDetail tempDetail : temp) {
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_SPECIFY_TIME)){
                                result=result&&checkTime(dateStart,dateEnd,tempDetail.getEffectiveDateStart(),tempDetail.getEffectiveDateEnd());
                            }
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_DAILY_REPEAT)){
                                if(ymdFormat.format(dateStart).equals(ymdFormat.format(dateEnd))){
                                    result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }else{
                                    result=result&&checkTime(timeStart,LocalTime.of(23,59,59),tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                    result=result&&checkTime(LocalTime.of(00,00,00),timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }
                            }
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_WEEKLY_REPEAT)){
                                if(ymdFormat.format(dateStart).equals(ymdFormat.format(dateEnd))){
                                    result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }else{
                                    result=result&&checkTime(timeStart,LocalTime.of(23,59,59),tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                    result=result&&checkTime(LocalTime.of(00,00,00),timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }
                            }
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_MONTHLY_REPEAT)){
                                if(ymdFormat.format(dateStart).equals(ymdFormat.format(dateEnd))){
                                    result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }else{
                                    result=result&&checkTime(timeStart,LocalTime.of(23,59,59),tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                    result=result&&checkTime(LocalTime.of(00,00,00),timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }
                            }
                        }
                    }else{
                        return true;
                    }
                }
            }else{
                return true;
            }
        }
        if(effectiveTimeType1.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_DAILY_REPEAT)){
            if(integralTimeRuleDetails!=null&&integralTimeRuleDetails.size()>0){
                for (IntegralTimeRuleDetail detail : integralTimeRuleDetails) {
                    LocalTime timeStart = detail.getEffectiveTimeStart();
                    LocalTime timeEnd = detail.getEffectiveTimeEnd();
                    List<IntegralTimeRuleDetail> temp = detail2.getIntegralTimeRuleDetails();
                    if(temp!=null&&temp.size()>0){
                        for (IntegralTimeRuleDetail tempDetail : temp) {
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_SPECIFY_TIME)){
                                Date tempDateEnd = tempDetail.getEffectiveDateEnd();
                                Date tempeDateStart = tempDetail.getEffectiveDateStart();
                                if(ymdFormat.format(tempDateEnd).equals(ymdFormat.format(tempeDateStart))){
                                    result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),dateToLocalTime(tempeDateStart),dateToLocalTime(tempDateEnd));
                                }else{
                                    result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),dateToLocalTime(tempeDateStart),LocalTime.of(23,59,59));
                                    result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),LocalTime.of(00,00,00),dateToLocalTime(tempDateEnd));

                                }
                            }
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_DAILY_REPEAT)){
                                result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                            }
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_WEEKLY_REPEAT)){
                                result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                            }
                            if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_MONTHLY_REPEAT)){
                                result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                            }
                        }
                    }else{
                        return true;
                    }
                }
            }else{
                return true;
            }
        }
        if(effectiveTimeType1.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_WEEKLY_REPEAT)){
            if(integralTimeRuleDetails!=null&&integralTimeRuleDetails.size()>0){
                for (IntegralTimeRuleDetail detail : integralTimeRuleDetails) {
                    String weeklySelection = detail1.getWeeklySelection();
                    if(StringUtils.isNotEmpty(weeklySelection)){
                        List<IntegralTimeRuleDetail> temp = detail2.getIntegralTimeRuleDetails();
                        if(temp!=null&&temp.size()>0){
                            LocalTime timeStart = detail.getEffectiveTimeStart();
                            LocalTime timeEnd = detail.getEffectiveTimeEnd();
                            for (IntegralTimeRuleDetail tempDetail : temp) {
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_SPECIFY_TIME)){
                                    Date tempDateEnd = tempDetail.getEffectiveDateEnd();
                                    Date tempeDateStart = tempDetail.getEffectiveDateStart();
                                    if(ymdFormat.format(tempDateEnd).equals(ymdFormat.format(tempeDateStart))){
                                        result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),dateToLocalTime(tempeDateStart),dateToLocalTime(tempDateEnd));
                                    }else{
                                        result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),dateToLocalTime(tempeDateStart),LocalTime.of(23,59,59));
                                        result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),LocalTime.of(00,00,00),dateToLocalTime(tempDateEnd));

                                    }
                                }
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_DAILY_REPEAT)){
                                    result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_WEEKLY_REPEAT)){
                                    result=result&&(checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd())
                                            ||checkWeekMonth(detail1.getWeeklySelection(),detail2.getWeeklySelection())
                                            );
                                }
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_MONTHLY_REPEAT)){
                                    result=result&&(checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd()));
                                }
                            }
                        }else{
                            return true;
                        }
                    }else{
                        return true;
                    }
                }
            }else{
                return true;
            }
        }
        if(effectiveTimeType1.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_MONTHLY_REPEAT)){
            if(integralTimeRuleDetails!=null&&integralTimeRuleDetails.size()>0){
                for (IntegralTimeRuleDetail detail : integralTimeRuleDetails) {
                    String monthlySelection = detail1.getMonthlySelection();
                    if(StringUtils.isNotEmpty(monthlySelection)){
                        List<IntegralTimeRuleDetail> temp = detail2.getIntegralTimeRuleDetails();
                        if(temp!=null&&temp.size()>0){
                            LocalTime timeStart = detail.getEffectiveTimeStart();
                            LocalTime timeEnd = detail.getEffectiveTimeEnd();
                            for (IntegralTimeRuleDetail tempDetail : temp) {
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_SPECIFY_TIME)){
                                    Date tempDateEnd = tempDetail.getEffectiveDateEnd();
                                    Date tempeDateStart = tempDetail.getEffectiveDateStart();
                                    if(ymdFormat.format(tempDateEnd).equals(ymdFormat.format(tempeDateStart))){
                                        result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),dateToLocalTime(tempeDateStart),dateToLocalTime(tempDateEnd));
                                    }else{
                                        result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),dateToLocalTime(tempeDateStart),LocalTime.of(23,59,59));
                                        result=result&&checkTime(detail.getEffectiveTimeStart(),detail.getEffectiveTimeEnd(),LocalTime.of(00,00,00),dateToLocalTime(tempDateEnd));

                                    }
                                }
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_DAILY_REPEAT)){
                                    result=result&&checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd());
                                }
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_WEEKLY_REPEAT)){
                                    result=result&&(checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd())
                                    );
                                }
                                if(effectiveTimeType2.equals(IntegralRuleDetail.EFFECTIVETIMETYPE_MONTHLY_REPEAT)){
                                    result=result&&(checkTime(timeStart,timeEnd,tempDetail.getEffectiveTimeStart(),tempDetail.getEffectiveTimeEnd())||
                                            checkWeekMonth(detail1.getMonthlySelection(),detail2.getMonthlySelection())
                                            );
                                }
                            }
                        }else{
                            return true;
                        }
                    }else{
                        return true;
                    }
                }
            }else{
                return true;
            }

        }
        return result;
    }

    public boolean checkWeekMonth(String s1,String s2){
        if(StringUtils.isNotEmpty(s1)&&StringUtils.isNotEmpty(s2)){
            List<String> list1 = Arrays.asList(s1.split(","));
            List<String> list2 = Arrays.asList(s2.split(","));
            boolean hasIntersection = list1.stream().anyMatch(list2::contains);
            if(hasIntersection){
                return false;
            }else{
                return true;
            }
        }else{
            return true;
        }
    }


    public boolean checkTime(Date dateStart1,Date dateEnd1,Date dateStart2,Date dateEnd2){
        if(dateStart1.getTime()<=dateStart2.getTime()&&dateStart2.getTime()<dateEnd1.getTime()){
            return false;
        }
        if(dateStart1.getTime()<dateEnd2.getTime()&&dateEnd2.getTime()<=dateEnd1.getTime()){
            return false;
        }
        return true;
    }
    public boolean checkTime(LocalTime timeStart1,LocalTime timeEnd1,LocalTime timeStart2,LocalTime timeEnd2){
        int start1=localTimeToInt(timeStart1);
        int end1=localTimeToInt(timeEnd1);
        int start2=localTimeToInt(timeStart2);
        int end2=localTimeToInt(timeEnd2);
        if(start1<=start2&&start2<end1){
            return false;
        }
        if(start1<end2&&end2<=end1){
            return false;
        }
        return true;
    }

    public int localTimeToInt(LocalTime time){
        String s = time.toString();
        if(s.split(":").length<3){
            s=s+":00";
        }
        s=s.replace(":","");
        int i = Integer.parseInt(s);
        return i;
    }

    public LocalTime dateToLocalTime(Date date){
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(date);
        Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis());
        LocalTime localTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalTime();
        return localTime;
    }

    public Date localTimeToDate(LocalTime time){
        SimpleDateFormat dateFormat2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat1=new SimpleDateFormat("yyyy-MM-dd");
        String ymd = dateFormat1.format(new Date());
        Date date = null;
        try {
            String s = time.toString();
            if(s.split(":").length<3){
                s=s+":00";
            }
            date = dateFormat2.parse(ymd + " " +s);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 删除积分规则
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralRuleService.deleteIntegralRuleByIds(ids));
    }
}
